Algorithm

A random hashing-based method for frequent elements problem.

Solves point query problem: given any value vv, let f(v)=i=1n𝟙[xi=v]f(v)=\sum_{i=1}^n \mathbb{1}[x_i=v] be the number of times vv appears in the stream.

Goal: return estimate f~(v)\tilde{f}(v) such that f(v)f~(v)f(v)+ϵknf(v) \leq \tilde{f}(v) \leq f(v) + \frac{\epsilon}{k}n.

Solving Frequent items: return all items for which f~(v)nk\tilde{f}(v) \geq \frac{n}{k}.

(assume access to a uniformly random hash function)

Count-Min Update:

return estimate f~(v)=𝐀[h(v)]\tilde{f}(v) = \mathbf{A}[h(v)]

\mathbf{A}[h(v)] = f(v) + \sum_{y \neq v} \mathbb{1}[h(y)=h(v)]\cdot f(y)$$ (this rightward summation term is error in frequency estimate) Expected error is $$ \begin{aligned} \mathbb{E}\left[\sum_{y \neq v} \mathbb{1}[h(y)=h(v)]\cdot f(y)\right] = \sum_{y \neq v} \mathbb{E}[\mathbb{1}[h(y)=h(v)]\cdot f(y)] \\ = \sum_{y \neq v} f(y) \mathbb{E}[\mathbb{1}[h(y)=h(v)]] = \frac{1}{m} \sum_{y \neq v} f(y) \leq \frac{n}{m} \end{aligned} ParseError: Can't use function '$' in math mode at position 74: …h(v)]\cdot f(y)$̲$ (this rightwa…

Bound of probability of error 2nm\geq \frac{2n}{m}?
Use Markov's inequality: Pr[yx:h(y)=h(x)f(y)2nm]12\mathrm{Pr}\left[ \sum_{y \neq x: h(y)=h(x)} f(y) \geq \frac{2n}{m} \right] \leq \frac{1}{2}

Claim: for any vv, with probability at least 1/21/2,

f(v)A[h(v)]f(v)+2nmf(v)\leq A[h(v)] \leq f(v) + \frac{2n}{m}

To solve point query with error ϵkn\frac{\epsilon}{k}n, set m=2kϵm=\frac{2k}{\epsilon}.

tt length mm arrays
Estimate f(v)f(v) with f~(v)=mini[t]Ai[hi(v)]\tilde{f}(v) = \min_{i∈[t]} A_i[h_i(v)].

#incomplete

See also


References

  1. G. Cormode and S. Muthukrishnan, “An improved data stream summary: the count-min sketch and its applications,” Journal of Algorithms, vol. 55, no. 1, pp. 58–75, Apr. 2005, doi: 10.1016/j.jalgor.2003.12.001.
  2. https://www.chrismusco.com/amlds2023/notes/lecture01.html#Count-Min_Sketch
  3. https://www.chrismusco.com/amlds2023/lectures/lec1_annotated.pdf ^4e6aed